package com.capgemini.business.mapper;

import com.capgemini.business.entity.Users;
import com.capgemini.business.entity.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UsersMapper {
    // Retrieve查询接口
    @Select("select * from users")
    List<Users> findAll();  // 返回列表

    // Create新增接口
    @Insert("insert into users (UserID, Username, Password, Email, Phone) " +
            "values (#{UserID}, #{Username}, #{Password}, #{Email}, #{Phone})")
    @Options(useGeneratedKeys = true, keyProperty = "UserID")  // 用于指定MyBatis在插入记录后自动生成并返回主键UserID。
    void insertUser(Users user);

    // Update修改接口
    @Update("update users set Username=#{Username}, Password=#{Password}, Email=#{Email}, Phone=#{Phone} where UserID=#{UserID}")
    void updateUser(Users user);

    // Delete删除接口
    @Delete("delete from users where UserID=#{UserID}")
    void deleteUser(int UserID);  // 通过UserID删除

    // Retrieve查询单个用户接口
    @Select("SELECT * FROM users WHERE UserID = #{UserID}")
    Users findUserById(int UserID);
}
